<template>
  <div>
    <div class="container">
      <el-row :gutter="10">
        <el-col :span="5">
          <el-select v-model="query.status" filterable clearable placeholder="请选择状态">
            <el-option :label="'待审核'" :value="1"> 待审核</el-option>
            <el-option :label="'正常'" :value="2"> 正常</el-option>
            <el-option :label="'禁用'" :value="3"> 禁用</el-option>
          </el-select>
        </el-col>
        <el-col :span="5"> <el-input v-model="query.phone" placeholder="电话" class="handle-input"
            clearable></el-input></el-col>
        <el-col :span="5"> <el-input v-model="query.name" placeholder="姓名" class="handle-input"
            clearable></el-input></el-col>
        <el-col :span="2"> <el-button type="primary" @click="handleSearch">搜索</el-button></el-col>
      </el-row>


      <el-table :data="tableData" border stripe class="table" ref="multipleTable" header-cell-class-name="table-header">
        <el-table-column prop="id" label="ID" align="center"></el-table-column>
        <el-table-column prop="name" label="名称" align="center"></el-table-column>
        <el-table-column prop="phone" label="手机号" align="center"></el-table-column>
        <el-table-column prop="sexName" label="性别" align="center"></el-table-column>
        <el-table-column prop="statusName" label="状态" align="center"></el-table-column>
        <el-table-column prop="workplace" label="所属驾校" align="center"></el-table-column>
        <el-table-column prop="address" label="地址" align="center"></el-table-column>
        <el-table-column prop="ranking" label="推荐指数" align="center"></el-table-column>
        <el-table-column prop="integral" label="积分" align="center"></el-table-column>
        <el-table-column label="操作" width="180" align="center">
          <template #default="scope">
            <el-button type="success" @click="handleExamine(scope.$index, scope.row)" v-if="scope.row.status == 1">审核
            </el-button>
            <el-button type="success" @click="handleEdit(scope.$index, scope.row)" v-if="scope.row.status != 1">编辑
            </el-button>
            <el-button type="primary" @click="handleInfo(scope.$index, scope.row)">查看
            </el-button>
          </template>
        </el-table-column>
      </el-table>

      <div class="pagination">
        <el-pagination background layout="total, prev, pager, next" :current-page="query.pno" :page-size="query.size"
          :total="query.total" @current-change="handlePageChange"></el-pagination>
      </div>

    </div>

    <!-- 编辑弹出框 -->
    <el-dialog :title="title" v-model="editVisible" width="70%" label-position="right" destroy-on-close>
      <el-form ref="form" :model="form" label-width="100px">
        <el-row :gutter="20">
          <el-col :span="8">
            <el-form-item label="名称">
              <el-input v-model="form.name" clearable :disabled=isDisabled></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="手机号">
              <el-input v-model="form.phone" clearable :disabled=isDisabled></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">

            <el-form-item label="身份证">
              <el-input v-model="form.card" clearable :disabled=isDisabled></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="推荐指数">
              <el-input v-model="form.ranking" clearable :disabled=isDisabled></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="积分">
              <el-input v-model="form.integral" clearable :disabled=isDisabled></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="预计收入">
              <el-input v-model="form.integral" clearable disabled></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="所属驾校">
              <el-input v-model="form.workplace" clearable :disabled=isDisabled></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="性别">
              <el-select v-model="form.sex" filterable clearable :disabled=isDisabled>
                <el-option :label="'男'" value="0"> 男</el-option>
                <el-option :label="'女'" value="1"> 女</el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="状态">
              <el-select v-model="form.status" filterable clearable :disabled=isDisabled>
                <el-option :label="'待审核'" value="1"> 待审核</el-option>
                <el-option :label="'正常'" value="2"> 正常</el-option>
                <el-option :label="'禁用'" value="3"> 禁用</el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="省">
              <el-input v-model="form.province" clearable :disabled=isDisabled></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="省">
              <el-input v-model="form.province" clearable :disabled=isDisabled></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="市">
              <el-input v-model="form.city" clearable :disabled=isDisabled></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="区">
              <el-input v-model="form.county" clearable :disabled=isDisabled></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="教练证编号">
              <el-input v-model="form.workplace" clearable :disabled=isDisabled></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="教练证图片">
              <el-image :src="form.certificateImage" :preview-src-list="[[form.certificateImage]]"
                style="width: 100px;"></el-image>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="身份证图片">
              <el-image :src="form.cardImage" :preview-src-list="[[form.cardImage]]" style="width: 100px;"></el-image>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <template #footer>
        <span class="dialog-footer">
          <el-button @click="editVisible = false">取 消</el-button>
          <el-button type="primary" @click="handle" v-if="!isDisabled">确 定</el-button>
        </span>
      </template>
    </el-dialog>
  </div>
</template>
  
<script>
import { ElMessage } from "element-plus";

export default {
  name: "bookList",
  data() {
    return {
      query: {
        pno: 1,  //当前页码
        total: 0,   //总共条数
        size: 4,   //每页多少条
        key: '', //搜索关键字
        type: '',
        status: ''
      },
      tableData: [],
      pageshow: true,
      editVisible: false,
      form: {},
      idx: -1,
      title: '',// 弹出框的标题
      isDisabled: false, // 是否禁用
    }
  },
  created() {
    this.getData();
  },

  methods: {
    getData() {
      let that = this;
      this.$http.post("coach/list", this.query)
        .then(res => {
          console.log(res)
          that.tableData = res.data.records
          that.query.pno = Number(res.data.current)  //当前是第几页
          that.query.total = Number(res.data.total) //总共条数
          that.query.size = Number(res.data.size)//每页多少条
        })
    },
    // 查看操作
    handleInfo(index, row) {
      this.idx = index;
      this.form = row;
      this.editVisible = true;
      this.title = '查看'
      this.isDisabled = true
    },
    // 编辑操作
    handleEdit(index, row) {
      this.idx = index;
      this.form = row;
      this.editVisible = true;
      this.title = '编辑'
      this.isDisabled = false
    },
    // 审核操作
    handleExamine(index, row) {
      this.idx = index;
      row.status="2"
      this.form = row;
      this.editVisible = true;
      this.isDisabled = false
      this.title = '审核'
    },
    // 对话框的确认操作
    handle() {
      let that = this;
      that.editVisible = false;
      this.$http.post('coach/update', this.form).then(
        res => {
          that.$message.success(res.msg);
          this.getData()
        }
      )
    },
    // 分页导航
    handlePageChange(val) {
      this.query.pno = val
      this.getData()
    },
    //搜索
    handleSearch() {
      this.getData()
    },
  }
}
</script>
  
<style scoped>
.table {
  margin-top: 20px;
}

.el-select {
  width: 100%;
}

.el-input {
  width: 100%;
}
</style>
  